<template>
  <div :class="'switch-tab-' + styleType">
    <div 
      class="item" 
      :class="{'item-cur': curTabIndex === index}"
      v-for="(item, index) in tabList" 
      :key="index"
      @click="tabClicked(index)"
    >
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tabList: {
      type: Array,
      default: []
    },
    curTabIndex: {
      type: Number,
      default: 0
    },
    styleType: {
      type: Number,
      default: 0
    }
  },
  methods: {
    tabClicked(index){
      this.$emit('itemClicked', index)
    }
  },
}
</script>

<style scoped>
/* style 0 */
.switch-tab-0{
  display: flex;
  justify-content: space-between;
}
.switch-tab-0 .item{
  flex-grow: 1;
  margin-right: 10px;
  height: 38px;
  line-height: 38px;
  border-radius: 38px;
  text-align: center;
  font-size: 14px;
  background-color: #ffffff;
}
.switch-tab-0 .item:last-child{
  margin: 0;
}
.switch-tab-0 .item-cur{
  color: #ffffff;
  background-color: #000000;
}

/* style 1 */
.switch-tab-1{
  display: flex;
  justify-content: space-between;
}
.switch-tab-1 .item{
  flex-grow: 1;
  height: 48px;
  line-height: 48px;
  text-align: center;
  font-size: 14px;
  color: #999999;
  background-color: #ffffff;
}
.switch-tab-1 .item:last-child{
  margin: 0;
}
.switch-tab-1 .item-cur{
  position: relative;
  color: #000000;
}
.switch-tab-1 .item-cur:after{
  display: block;
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  margin-left: -20px;
  width: 40px;
  height: 2px;
  background-color: #000000;
}

/* style 2 */
.switch-tab-2{
  display: flex;
  padding: 3px 0 0 10px;
  background-color: #ffffff;
}
.switch-tab-2 .item{
  height: 48px;
  line-height: 45px;
  text-align: center;
  font-size: 14px;
  color: #999999;
  padding-right: 30px;;
}
.switch-tab-2 .item span{
  color: #000000;
  display: inline-block;
  border-bottom: 3px solid #fff;
}
.switch-tab-2 .item:last-child{
  margin: 0;
}
.switch-tab-2 .item-cur span{
  color: #d50721;
  border-bottom: 3px solid #d50721;
}
</style>